using System.Linq;
using Engine;
using Engine.Graphics;
using Game;

namespace RuthlessConquest {
    public class PlayerLabelWidget : CanvasWidget {
        public GameScreen GameScreen;
        public RectangleWidget PanelRectangle;
        public RectangleWidget ShipRectangle;
        public RectangleWidget FlagRectangle;
        public LabelWidget Label;
        public RectangleWidget PlatformRectangle;
        public RectangleWidget SatelliteRectangle;
        public ClickableWidget SatelliteClickableWidget;
        public RectangleWidget MenuRectangle;
        public ClickableWidget MenuClickableWidget;

        public StackPanelWidget RootPanel;
        public Widget OriginalContainer;
        public LabelWidget Statistic1Label;
        public LabelWidget Statistic2Label;

        public int LabelIndex;
        public Player publicPlayer;
        public const string fName = "RCPlayerLabelWidget";

        public bool IsSatelliteButtonClicked {
            get {
                if (SatelliteClickableWidget == null) {
                    return false;
                }
                return SatelliteClickableWidget.IsClicked;
            }
        }

        public Player Player {
            get => publicPlayer;
            set {
                publicPlayer = value;
                IsVisible = value != null;
            }
        }

        public PlayerLabelWidget(GameScreen gameScreen, int labelIndex) {
            GameScreen = gameScreen;
            LabelIndex = labelIndex;
            Size = new Vector2(-1f, -1f);
            IsHitTestVisible = false;
            RootPanel = new StackPanelWidget { Direction = LayoutDirection.Vertical };
            if (LabelIndex == 0) {
                HorizontalAlignment = WidgetAlignment.Center;
                VerticalAlignment = WidgetAlignment.Near;
                CanvasWidget originalContainer = new();
                PanelRectangle = new RectangleWidget {
                    Size = new Vector2(362f, 34f),
                    Subtexture = new Subtexture(Textures.Gui.PlayerPanel, Vector2.Zero, Vector2.One),
                    OutlineColor = Color.Transparent
                };
                originalContainer.Children.Add(PanelRectangle);
                SatelliteClickableWidget = new ClickableWidget { SoundName = "RCSounds/Click", IsEnabled = false };
                CanvasWidget satelliteClickableWidgetContainer = new() {
                    Size = new Vector2(80f, 34f), HorizontalAlignment = WidgetAlignment.Near, VerticalAlignment = WidgetAlignment.Center
                };
                satelliteClickableWidgetContainer.AddChildren(SatelliteClickableWidget);
                originalContainer.Children.Add(satelliteClickableWidgetContainer);
                MenuClickableWidget = new ClickableWidget { SoundName = "RCSounds/Click" };
                CanvasWidget menuClickableWidgetContainer = new() {
                    Size = new Vector2(80f, 34f), HorizontalAlignment = WidgetAlignment.Far, VerticalAlignment = WidgetAlignment.Center
                };
                menuClickableWidgetContainer.AddChildren(MenuClickableWidget);
                originalContainer.Children.Add(menuClickableWidgetContainer);
                StackPanelWidget obj4 = new() {
                    Margin = new Vector2(0f, 3f), HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Near
                };
                Label = new LabelWidget { FontScale = 0.75f, DropShadow = false, Margin = new Vector2(3f, 0f) };
                obj4.Children.Add(Label);
                PlatformRectangle = new RectangleWidget {
                    Size = new Vector2(20f, 20f), OutlineColor = Color.Transparent, Margin = new Vector2(5f, 0f)
                };
                obj4.Children.Add(PlatformRectangle);
                originalContainer.Children.Add(obj4);
                SatelliteRectangle = new RectangleWidget {
                    Size = new Vector2(26f, 26f),
                    Margin = new Vector2(18f, 2f),
                    HorizontalAlignment = WidgetAlignment.Near,
                    VerticalAlignment = WidgetAlignment.Near,
                    Subtexture = new Subtexture(Textures.Gui.Satellite, Vector2.Zero, Vector2.One),
                    FillColor = Colors.ForeDisabled,
                    OutlineColor = Color.Transparent
                };
                originalContainer.Children.Add(SatelliteRectangle);
                MenuRectangle = new RectangleWidget {
                    Size = new Vector2(26f, 26f),
                    Margin = new Vector2(18f, 2f),
                    HorizontalAlignment = WidgetAlignment.Far,
                    VerticalAlignment = WidgetAlignment.Near,
                    Subtexture = new Subtexture(Textures.Gui.Menu, Vector2.Zero, Vector2.One),
                    FillColor = Colors.Fore,
                    OutlineColor = Color.Transparent
                };
                originalContainer.Children.Add(MenuRectangle);
                RootPanel.Children.Add(originalContainer);
                OriginalContainer = originalContainer;
            }
            else {
                StackPanelWidget originalContainer = new() { IsHitTestVisible = false, Margin = new Vector2(6f, 2f) };
                PlatformRectangle = new RectangleWidget {
                    Size = new Vector2(20f, 20f),
                    OutlineColor = Color.Transparent,
                    Margin = new Vector2(5f, 0f),
                    VerticalAlignment = WidgetAlignment.Center
                };
                originalContainer.Children.Add(PlatformRectangle);
                Label = new LabelWidget {
                    FontScale = 0.75f, DropShadow = false, Margin = new Vector2(3f, 0f), VerticalAlignment = WidgetAlignment.Center
                };
                originalContainer.Children.Add(Label);
                ShipRectangle = new RectangleWidget {
                    Size = new Vector2(20f, 20f),
                    OutlineColor = Color.Transparent,
                    Margin = new Vector2(6f, 0f),
                    VerticalAlignment = WidgetAlignment.Center
                };
                originalContainer.Children.Add(ShipRectangle);
                FlagRectangle = new RectangleWidget {
                    Size = new Vector2(36f, 18f),
                    OutlineColor = Color.Transparent,
                    Margin = new Vector2(8f, 0f),
                    VerticalAlignment = WidgetAlignment.Center
                };
                originalContainer.Children.Add(FlagRectangle);
                RootPanel.Children.Add(originalContainer);
                OriginalContainer = originalContainer;
            }
            if (SettingsManager.DisplayPlayerStatistics) {
                CreateStatisticsPanel();
                RootPanel.Children.Add(Statistic1Label);
                RootPanel.Children.Add(Statistic2Label);
            }
            Children.Add(RootPanel);
        }

        public void CreateStatisticsPanel() {
            Statistic1Label = new LabelWidget { Color = Color.Transparent, FontScale = 0.75f, Margin = new Vector2(6f, 2f) };
            Statistic2Label = new LabelWidget { Color = Color.Transparent, FontScale = 0.75f, Margin = new Vector2(6f, 2f) };
        }

        public override void Update() {
            if (Player?.Game == null) {
                return;
            }
            if (SettingsManager.DisplayPlayerStatistics) {
                if (Player.Faction == Faction.None) {
                    if (Statistic1Label != null) {
                        RootPanel.Children.Remove(Statistic1Label);
                        RootPanel.Children.Remove(Statistic2Label);
                    }
                }
                else if (Statistic1Label == null) {
                    CreateStatisticsPanel();
                    RootPanel.Children.Add(Statistic1Label);
                    RootPanel.Children.Add(Statistic2Label);
                }
            }
            UpdateAlignment();
            bool lost = Player.Status < FactionStatus.Undecided;
            PanelRectangle?.FillColor = Player.GetColor(Player.Faction);
            if (FlagRectangle != null) {
                //Player.Game.PlayersModule.PlayerAddresses.TryGetValue(Player.Guid, out string addressString);
                //Player.Game.PlayersModule.PlayerAddresses.Values.Count(s => s == addressString);
                Player.Game.PlayersModule.PlayerLocations.TryGetValue(Player.Guid, out string value);
                Texture2D texture2D = value != null ? IpLocationManager.GetFlagTexture(value) : null;
                if (texture2D != null
                    && SettingsManager.ShowFlags) {
                    FlagRectangle.Subtexture = new Subtexture(texture2D, Vector2.Zero, Vector2.One);
                    FlagRectangle.FillColor = Color.White;
                    FlagRectangle.IsVisible = true;
                    ShipRectangle.IsVisible = false;
                }
                else {
                    ShipRectangle.Subtexture = new Subtexture(lost ? Textures.Skull : Ship.GetTexture(Player.Faction), Vector2.Zero, Vector2.One);
                    ShipRectangle.FillColor = Ship.GetColor(Player.Faction);
                    ShipRectangle.IsVisible = true;
                    FlagRectangle.IsVisible = false;
                }
            }
            Label.Color = Player.GetColor(lost ? Faction.Neutral : Player.Faction);
            PlatformRectangle.Subtexture = new Subtexture(Player.GetPlatformTexture(Player.Platform), Vector2.Zero, Vector2.One);
            PlatformRectangle.IsVisible = Player.GetPlatformTexture(Player.Platform) != null;
            PlatformRectangle.FillColor = Player.GetColor(lost ? Faction.Neutral : Player.Faction);
            string text = IsPlayerColocated(Player) ? Player.Name + "*" : Player.Name;
            Label.Text = Player.Faction == Faction.None ? "Spectating" : text;
            if (MenuRectangle != null) {
                MenuRectangle.FillColor = MenuClickableWidget != null && MenuClickableWidget.IsPressed ? Colors.Fore : Label.Color;
                MenuRectangle.RenderTransform =
                    Matrix.CreateTranslation((X: (0f - MenuRectangle.ActualSize.X) / 2f, Y: (0f - MenuRectangle.ActualSize.Y) / 2f, Z: 0f))
                    * Matrix.CreateScale((float)MathUtils.Max(MathUtils.Sin(2.0 * Time.RealTime) - 0.800000011920929, 0.0) + 1f)
                    * Matrix.CreateTranslation((X: MenuRectangle.ActualSize.X / 2f, Y: MenuRectangle.ActualSize.Y / 2f, Z: 0f));
            }
            if (MenuClickableWidget != null
                && MenuClickableWidget.IsClicked) {
                DialogsManager.ShowDialog(null, new GameMenuDialog(GameScreen, false));
            }
            if (SatelliteClickableWidget != null) {
                SatelliteClickableWidget.IsEnabled = Player.Game.StepModule.IsGameStarted
                    && Player.Game.StepModule.CountdownStepsLeft <= 0
                    && Player.Faction != Faction.None
                    && Player.Status >= FactionStatus.Undecided;
            }
            if (SatelliteRectangle != null) {
                SatelliteRectangle.FillColor = SatelliteClickableWidget != null && SatelliteClickableWidget.IsPressed ? Colors.Fore :
                    Player.AreSatellitesEnabled && SatelliteClickableWidget.IsEnabled ? Ship.GetColor(Player.Faction) : Colors.ForeDisabled;
            }
            if (SettingsManager.DisplayPlayerStatistics
                && Player.Faction != Faction.None) {
                Statistic1Label.Color = Label.Color;
                Statistic2Label.Color = Label.Color;
                if (LabelIndex == 0) {
                    float maxProduction = 0;
                    float currentProduction = 0;
                    int shipsCountInPlanets = 0;
                    foreach (Planet planet in Player.PlanetsModule.FactionOwnPlanets[(int)Player.Faction]) {
                        maxProduction += planet.SizeClass switch {
                            0 => 3600f / 133f,
                            1 => 3600f / 93f,
                            2 => 3600f / 53f,
                            _ => 0
                        };
                        currentProduction += planet.ProductionRateForDisplay;
                        shipsCountInPlanets += planet.ShipsCount;
                    }
                    Statistic1Label.Text = string.Format(
                        LanguageControl.Get(fName, "1"),
                        maxProduction.ToString("0"),
                        100 - Player.FactionProductionFactor,
                        currentProduction.ToString("0")
                    );
                    int flyingShipsCount = Player.ShipsModule.FactionOwnShips[(int)Player.Faction];
                    Statistic2Label.Text = string.Format(
                        LanguageControl.Get(fName, "3"),
                        shipsCountInPlanets + flyingShipsCount,
                        flyingShipsCount.ToString()
                    );
                }
                else {
                    float maxProduction = 0;
                    foreach (Planet planet in Player.PlanetsModule.FactionOwnPlanets[(int)Player.Faction]) {
                        maxProduction += planet.SizeClass switch {
                            0 => 3600f / 133f,
                            1 => 3600f / 93f,
                            2 => 3600f / 53f,
                            _ => 0
                        };
                    }
                    Statistic1Label.Text = string.Format(
                        LanguageControl.Get(fName, "2"),
                        maxProduction.ToString("0"),
                        100 - Player.FactionProductionFactor
                    );
                    Statistic2Label.Text = string.Format(
                        LanguageControl.Get(fName, "4"),
                        Player.ShipsModule.FactionOwnShips[(int)Player.Faction].ToString()
                    );
                }
            }
        }

        public void UpdateAlignment() {
            int num = 0;
            foreach (PlayerLabelWidget playerLabel in GameScreen.PlayerLabels) {
                if (playerLabel.IsVisible) {
                    num++;
                }
            }
            switch (num) {
                case 1: {
                    if (LabelIndex == 0) {
                        HorizontalAlignment = WidgetAlignment.Center;
                        VerticalAlignment = WidgetAlignment.Near;
                        OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                        Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                        Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                    }
                    break;
                }
                case 2:
                    switch (LabelIndex) {
                        case 0:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                        case 1:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                    }
                    break;
                case 3:
                    switch (LabelIndex) {
                        case 0:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                        case 1:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 2:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                    }
                    break;
                case 4:
                    switch (LabelIndex) {
                        case 0:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                        case 1:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 2:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                        case 3:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                    }
                    break;
                case 5:
                    switch (LabelIndex) {
                        case 0:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                        case 1:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 2:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                        case 3:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 4:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                    }
                    break;
                case 6:
                    switch (LabelIndex) {
                        case 0:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                        case 1:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 2:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                        case 3:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                        case 4:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 5:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                    }
                    break;
                case >= 7:
                    switch (LabelIndex) {
                        case 0:
                            HorizontalAlignment = WidgetAlignment.Center;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Center;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Center;
                            break;
                        case 1:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 2:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Near;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                        case 3:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        //case 4: Alignment = new Vector2(-0.33f, 1f); break;
                        //case 5: Alignment = new Vector2(0.33f, 1f); break;
                        case 4:
                            HorizontalAlignment = WidgetAlignment.Near;
                            VerticalAlignment = WidgetAlignment.Center;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Near;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Near;
                            break;
                        case 5:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Center;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                        case 6:
                            HorizontalAlignment = WidgetAlignment.Far;
                            VerticalAlignment = WidgetAlignment.Far;
                            OriginalContainer.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic1Label?.HorizontalAlignment = WidgetAlignment.Far;
                            Statistic2Label?.HorizontalAlignment = WidgetAlignment.Far;
                            break;
                    }
                    break;
            }
        }

        public static bool IsPlayerColocated(Player player) {
            if (player.Game.PlayersModule.PlayerAddresses.TryGetValue(player.Guid, out string addressString)) {
                return player.Game.PlayersModule.PlayerAddresses.Values.Count(s => s == addressString) > 1;
            }
            return false;
        }
    }
}